#!/bin/sh

#
# Test streaming a firmware update through fwup with framing.
# This simulates the case where there's no local storage to hold
# the firmware update while it is being applied.
#

. "$(cd "$(dirname "$0")" && pwd)/common.sh"

cat >$CONFIG <<EOF
file-resource TEST {
	host-path = "${TESTFILE_1K}"
}

task complete {
	on-resource TEST { raw_write(1) }
}
EOF

# Create the firmware file like normal
$FWUP_CREATE -c -f $CONFIG -o $FWFILE

# Pipe the framed contents (in super small chunks) on the .fw file to fwup
cat $FWFILE | $FRAMING_HELPER -n 50 -e \
    | $FWUP_APPLY -q --framing -a -d $IMGFILE -i - -t complete

# Check that the test file ends up in the right place
cmp_bytes 1024 $TESTFILE_1K $IMGFILE 0 512
